<template>
  <div class="exportHistory">
    <div class="searchBar">
      <el-date-picker
        v-model="searchParams.dates"
        type="datetimerange"
        :clearable="false"
        value-format="yyyy-MM-dd HH:mm:ss"
        format="yyyy-MM-dd HH:mm:ss"
        :picker-options="pickerOptions"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        align="right">
      </el-date-picker>
      <el-button style="margin-left: 14px;" type="primary" @click="handleSearch">查询</el-button>
    </div>
  </div>
</template>
<script>
import moment from 'moment';
import { getShopImportHistory } from '@/api/order'
export default {
  data() {
    const startTime = moment().subtract(1, 'days').format("yyyy-MM-DD 00:00:00");
    const endTime = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
    return {
      searchParams: {
        dates: [startTime, endTime],
      },

      tableData: [],
      total: 0,
      pickerOptions: {
        shortcuts: [{
          text: '最近一天',
          onClick(picker) {
            const start = moment().subtract(1, 'days').format("yyyy-MM-DD 00:00:00");
            const end = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
            picker.$emit('pick', [
              moment(start)["_d"], moment(end)["_d"]
            ]);
          }
        }, {
          text: '最近一周',
          onClick(picker) {
            const start = moment().subtract(7, 'days').format("yyyy-MM-DD 00:00:00");
            const end = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
            picker.$emit('pick', [
              moment(start)["_d"], moment(end)["_d"]
            ]);
          }
        },  {
          text: '最近半个月',
          onClick(picker) {
            const start = moment().subtract(15, 'days').format("yyyy-MM-DD 00:00:00");
            const end = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
            picker.$emit('pick', [
              moment(start)["_d"], moment(end)["_d"]
            ]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const start = moment().subtract(30, 'days').format("yyyy-MM-DD 00:00:00");
            const end = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
            picker.$emit('pick', [
              moment(start)["_d"], moment(end)["_d"]
            ]);
          }
        }, {
          text: '最近二个月',
          onClick(picker) {
            const start = moment().subtract(60, 'days').format("yyyy-MM-DD 00:00:00");
            const end = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
            picker.$emit('pick', [
              moment(start)["_d"], moment(end)["_d"]
            ]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const start = moment().subtract(90, 'days').format("yyyy-MM-DD 00:00:00");
            const end = moment().subtract(1, 'days').format("yyyy-MM-DD 23:59:59");
            picker.$emit('pick', [
              moment(start)["_d"], moment(end)["_d"]
            ]);
          }
        }]
      },
    }
  },
  created() {
    this.initData();
  },
  methods: {
    initData() {
      const params = {
        startTime: this.searchParams.dates[0],
        endTime: this.searchParams.dates[1],
      }
      getShopImportHistory(params).then(res => {
        const { total, rows } = res;
        this.tableData = rows;
        this.total = total;
      })
    },
    handleSearch() {
      this.initData();
    },
  }
}
</script>
<style lang="scss" scoped>
div.exportHistory {
  div.searchBar {
    margin-bottom: 20px;
  }
}
</style>
